package nacos_init

import (
	"encoding/json"

	"github.com/ryon-wen/own-utils/own"

	"2106A-zg6/baidu/srv/internal/config"
	"2106A-zg6/baidu/srv/models"
)

func NacosClient(c config.Config) {
	na := c.Nacos
	nacos, err := own.InitNacos(&own.Nacos{
		IpAddr:      na.Post,
		Port:        uint64(na.Port),
		NamespaceId: na.NamespaceId,
		DataId:      na.DataId,
		Group:       na.Group,
	})
	if err != nil {
		panic(err)
	}
	//fmt.Println(nacos)
	var nacosCon NacosContent
	json.Unmarshal([]byte(nacos), &nacosCon)
	//fmt.Println(nacosCon)
	models.MysqlInit(nacosCon.Mysql)
}

type NacosContent struct {
	Mysql     string
	Redis     string
	IPAddress string
	Consul    struct {
		Name string
		Host string
		Port int64
	}
	AliPay struct {
		AppId        string
		PrivateKey   string
		AliPublicKey string
	}
	Es struct {
		Host     string
		Port     int64
		IndexKey string
	}
}
